#pragma once
#include "precompiled.h"
#include "IMLObjects.h"

namespace IcyCrystal {
	class Symbol;
	class Arg;
	class Namespace;

	typedef map<const string, Symbol*> _symbolMap;

	enum Scope{
		SCOPE_GLOBAL, SCOPE_PARAM, SCOPE_LOCAL,
		SCOPE_TEMP, SCOPE_CONSTANT,
		SCOPE_UNNAMED_PARA, SCOPE_NAMED_PARA
	};

	class Symbol {
	public:
		string symbolName;
		Scope scope;
		int level;
		Type type;

		Arg* location;
		// Main Locations
		LocationList* locations;

		union{
			string* stringConst;
			//SyntaxTreeList* arrayConst;
			SyntaxTree* exprConst;
			struct {
				SymbolList* paramDeclaration;
				SyntaxTreeList* functionBody;
				Namespace* functionNamespace;
			} function;
		} consts;
	};

	class Namespace {
	public:
		Namespace() : level(0){}

		_symbolMap SymbolMap;
		_symbolMap ConstantMap;
		_symbolMap FunctionMap;
		vector<Type*> types;

		Scope scope;
		int level;

		Namespace* up;

		/** Looks for symbols in current and parent namespace */
		Symbol* findSymbol(const string& symbolName);
	};

}
